package com.nervenets.web.entity;


import com.alibaba.fastjson.JSONObject;
import com.nervenets.utils.StringUtils;
import com.nervenets.web.hibernate.DomainObject;

/**
 * Created by shengshibotong.com.
 * User: Joe by 12-12-24 上午9:07
 */
public class Result extends JSONObject {
    public Result() {
    }

    public Result(boolean status) {
        put("status", status);
    }

    public Result(boolean status, String message) {
        put("status", status);
        put("message", message);
    }

    public Result(boolean status, int code) {
        put("status", status);
        put("code", code);
    }

    public Result(boolean status, int code, String message) {
        put("status", status);
        put("code", code);
        put("message", message);
    }

    public Result(boolean status, int code, DomainObject data) {
        put("status", status);
        put("code", code);
        put("data", data);
    }

    public static Result failed() {
        return new Result(false);
    }

    public static Result failed(String message) {
        return new Result(false, message);
    }

    public static Result failed(int code, String message) {
        return new Result(false, code, message);
    }

    public static Result success() {
        return new Result(true);
    }

    public static Result success(String message) {
        return new Result(true, message);
    }

    public void setStatus(boolean status) {
        put("status", status);
    }

    public int getCode() {
        return getIntValue("code");
    }

    public void setCode(int code) {
        put("code", code);
    }

    public Object getData() {
        return get("data");
    }

    public void setData(Object data) {
        put("data", data);
    }

    public String getVersion() {
        return getString("version");
    }

    public void setVersion(String version) {
        put("version", version);
    }

    public String getMessage() {
        return getString("message");
    }

    public void setMessage(String message) {
        put("message", message);
    }

    @Override
    public String toString() {
        return StringUtils.toJson(this);
    }
}
